let dom = require("../../utils/dom.js");
let https = require("../../utils/https.js");
require("../../assets/css/index.less");
let axios = require("axios");
// 2.引入当前样式表
require("../../assets/fonts/iconfont.css");
require("./circle.less");
dom.ready(function () {
  dom.createFoot(2);
  dom.addEvent(".add-dynamic", function () {
    location.href = "dyn.html";
  });
  dom.addEvent(".img-class", function () {
    location.href = "datelis.html?id=1";
  });

  https.get("/api/circles/opinionList", (res) => {
    let count = 0;
    if (res.errno == 0) {
      res.data.forEach((v, i) => {
        if (
          v.releaseProvinceId &&
          v.releaseCityId &&
          v.releaseProvinceId != v.releaseCityId
        ) {
          console.log(v.imgUrls.length>1);
          dom.$(".add-New-cont").innerHTML += `
        <section class="sec-mb mar-top20">
          <div class="head-name disflex">
            <div class="head-icon"></div>
            <div class="user-mess">
              <p class="user">用户名</p>
              <p class="city"><span id="pro_id"></span> <span id="city_id"></span></p>
            </div>
          </div>
          <p class="user-word f14">
            ${v.content}
          </p>
          <div class="disflex ${
            v.imgUrls.length > 1 ? "img-list-one" : "img-list-two"
          }" id="creatDiv">
          </div>
        </section>
        <div class="slicer"></div>
        `;

          getAddress(v.releaseProvinceId, v.releaseCityId).then((res) => {
            dom.$("#pro_id")[count].innerHTML = res[0].name;
            dom.$("#city_id")[count].innerHTML = res[1].name;

            for (let index = 0; index < v.imgUrls.length; index++) {
              dom.$("#creatDiv")[count].innerHTML += `<div>
                   <img src="${
                     https.BASE_URL + v.imgUrls[index]
                   }" alt="图片不存在">
                  </div>`;
            }
            count++;
          });
        }
      });
    }
  });
  async function getAddress(proId, cId) {
    let pId = await axios.get(https.BASE_URL + "/api/shared/province");
    let pArr = pId.data.data.filter((v) => {
      return v.id == proId;
    });

    let ccId = await axios.get(
      https.BASE_URL + "/api/shared/city?provinceId=" + pArr[0].id
    );

    let cArr = ccId.data.data.filter((v) => {
      return v.id == cId;
    });

    return [...pArr, ...cArr];
  }
});
